home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / metamail / contrib / ServiceMail / src / shell / waisget < prev    next >
Encoding:
Text File  |  1993-05-08  |  1.7 KB  |  94 lines

  1. #!/bin/csh
  2.  
  3. # Script to retrieve WAIS documents for ServiceMail
  4. # Jim Davis Aug 25 1992
  5.  
  6. if ($#argv == 0) goto usage
  7.  
  8. set source = $HOME/.wais-sources
  9. set boundary = DOCUMENT
  10. set question = $1
  11. shift
  12.  
  13. while ($#argv > 0)
  14.   switch ($1)
  15.   case -s:
  16.    shift
  17.    if ($#argv < 1) goto usage
  18.    set source = $1
  19.    shift
  20.    breaksw
  21.  case -b:
  22.    shift
  23.    if ($#argv < 1) goto usage
  24.    set boundary = $1
  25.    shift
  26.    breaksw
  27.  default:
  28.    goto usage
  29.    breaksw
  30.  endsw
  31. end
  32.  
  33. # remove any garbage from head of the message, e.g. mail headers
  34.  
  35. set tempq = /tmp/question$$
  36.     
  37. if (-e $question) else
  38.  echo Question file $question does not exist.
  39.  exit 1
  40. endif
  41.  
  42. if (-d $source) else
  43.  echo WAIS sources directory $source does not exist.
  44.  exit 1
  45. endif
  46.  
  47. awk '/\(:question/ {ok=1}\
  48.      /^Searching:/ {ok=0}\
  49.                    {if (ok == 1) print}' $question > $tempq
  50.  
  51. # Now find out how many documents there are
  52. set temp = /tmp/waisq$$
  53. set result = /tmp/doc$$
  54. waisq -f $tempq -s $source -g >& $temp
  55. echo "" >> $temp
  56. set count = `tail -1 $temp | sed -e 's/^.*Found //' | sed -e 's/ item.*$//'`
  57.  
  58. echo -n Retrieving $count document
  59. if ($count == 1) then
  60.  echo ""
  61. else
  62.  echo "s"
  63. endif
  64.  
  65. # Now get each one.
  66.  
  67. set i = 1
  68.  
  69. rm $temp
  70. touch $temp
  71.  
  72. while ($i <= $count)
  73.  # insert MIME boundary
  74.  echo --${boundary} >> $temp
  75.  waisq -s $source -f $tempq -v $i > $result
  76.  if ("`head -1 $result | awk '/Mime Version/{print 1}'`" != 1) then
  77.    # if it is not a MIME document, insert blank line
  78.    echo "" >> $temp
  79.  endif
  80.  cat $result >> $temp
  81.  @ i ++
  82. end
  83. # final MIME boundary
  84. echo --${boundary}-- >> $temp
  85.  
  86. cat $temp
  87.  
  88. rm $tempq $temp $result
  89. exit 0
  90.  
  91. usage:
  92.  echo "usage: `basename $0` QUESTION [-s SOURCE-DIR] [-b BOUNDARY-STRING]"
  93.  exit 1
  94.